--交易日间隔获取
CREATE OR REPLACE FUNCTION public.getwd(date, int)
 RETURNS date
 LANGUAGE plpgsql
 STRICT
AS $function$
declare
  s date := $1;
  m int := $2;
  days int :=$2;
  td date;
begin
	for d in 1..m loop
		s := s-1;
		--特殊节日处理 元旦
		if s=date'20180101' then
			s := s-1;
		end if;
		while extract(isodow from s) in (6,7) loop
			s := s-1;
		end loop;
		
	end loop;
	return s;
end 
$function$
